//== 流程示例-列表页
let sampleWorkFlowList = function () {
    /**
     * 初始化列表
     */
    let initTable = function () {
        let options = {
            layout: {
                // 默认的表格高度可以放下2行查询条件，如果查询条件较多，可以通过下方代码设置高度
                height: function () {
                    let minHeight = 300;
                    let height = EUtil.getViewPort().height - 340;
                    return Math.max(height, minHeight);
                }
            },
            // 列配置
            columns: [
                {
                    field: 'id',
                    title: '#',
                    sortable: false, // 禁用此列排序
                    width: 40,
                    selector: {class: 'e-checkbox--solid'}
                },
                {
                    field: 'processInstanceId',
                    title: '流程实例id',
                    template: function (row, index, datatable) {
                        return row.processInstanceId ? row.processInstanceId : '-';
                    }
                },
                {
                    field: 'leaveType',
                    title: '请假类型',
                    dictType: 'leaveType'
                },
                {
                    field: 'reason',
                    title: '原因'
                },
                {
                    field: 'startDate',
                    title: '开始时间'
                },
                {
                    field: 'endDate',
                    title: '结束时间'
                },
                {
                    field: 'editUser',
                    title: '编辑人'
                },
                {
                    field: 'editDate',
                    title: '编辑时间'
                },
                {
                    field: 'workFlowStatus',
                    title: '状态',
                    width: 180
                },
                {
                    field: 'Actions',
                    width: 130,
                    title: '操作',
                    sortable: false,
                    locked: {
                        right: 'md'
                    },
                    template: function (row, index, datatable) {
                        let _btn = '';
                        if (ETool.hasPermissions('sample:work:flow:save')) {
                            _btn += '<a href="#" onclick="ETool.editById(this, \'' + row.id + '\')" class="' + ETool.ACTIONS_INFO + '" title="编辑">\
                                <i class="la la-edit"></i>\
                            </a>';
                        }
                        if (ETool.hasPermissions('sample:work:flow:delete')) {
                            _btn += '<a href="#" onclick="ETool.deleteById(this, \'' + row.id + '\')" class="' + ETool.ACTIONS_DANGER + '" title="删除">\
                                <i class="la la-trash"></i>\
                            </a>';
                        }
                        let leaveType = ETool.getSysDictObjectByQuery('leaveType', row.leaveType).name;
                        if(EUtil.isBlank(row.processInstanceId)){
                            _btn += '<a href="#" onclick="EWorkFlow.attemptStartProcessInstance(\'leave\', \'' + row.id + '\', \'[' + leaveType + ']' + row.reason + '\', \'' + ETool.getBaseUrl() + 'info/' + row.id + '\')" class="' + ETool.ACTIONS_SUCCESS + '" title="提交">\
                                <i class="la la-send"></i>\
                            </a>';
                        }
                        if(EUtil.isNotBlank(row.processInstanceId)){
                            _btn += '<a href="#" onclick="EWorkFlow.openProcessProgressWithBusinessKey(\'' + row.id + '\')" class="' + ETool.ACTIONS_SUCCESS + '" title="流程跟踪">\
                                <i class="la la-search"></i>\
                            </a>';
                        }
                        return _btn;
                    }
                }
            ]
        };
        sampleWorkFlowList.dataTable = ETool.initDataTable(options);
    };



    return {
        //== 初始化页面
        init: function () {
            ETool.setBaseUrl(basePath + '/auth/sample/work/flow/');
            initTable();
        }
    };
}();
/**
 * 当前tab激活时是否需要重新加载数据
 *
 * @return {boolean} true/false
 */
ETab.needSubmitForm = function () {
    return true;
};
//== 初始化
$(document).ready(function () {
    sampleWorkFlowList.init();
});